package emergency;

import movement.Location;
import dispatch.DispatchCenter;

/**
 * A class for creating a new TrafficAccident
 */
public class TrafficAccident extends Emergency {

	/**
	 * Variable registering the amount of cars involved in this TrafficAccident
	 */
	private int numberOfCars;

	/**
	 * Variable registering the amount of injured people involved in this
	 * TrafficAccident
	 */
	private int numberOfInjured;

	/**
	 * Initialize this new TrafficAccident
	 * 
	 * @param location
	 *            The location of this TrafficAccident
	 * 
	 * @param severity
	 *            The severity of this TrafficAccident
	 * 
	 * @param numberOfCars
	 *            The amount of cars involved in this TrafficAccident
	 * 
	 * @param numberOfInjured
	 *            The amount of people injured in this TrafficAccident
	 * 
	 * @param dispatchCenter
	 *            The dispatchCenter where this trafficAccident has to be added
	 *            to
	 * 
	 * @post The location of this TrafficAccident is set to the given location
	 * 
	 * @post The severity of this TrafficAccident is set to the given severity
	 * 
	 * @post The amount of people injured in this TrafficAccident is set to the
	 *       given amount
	 * 
	 * @post The amount of cars involved in this TrafficAccident is set to the
	 *       given amount
	 * 
	 * @post The dispatchCenter of this trafficAccident is set to the given
	 *       dispatchCenter
	 * 
	 * @post This trafficaccident is added to the given dispatchcenter
	 */
	public TrafficAccident(Location location, Severity severity,
			DispatchCenter dispatchCenter, int numberOfCars, int numberOfInjured) {
		super(location, severity, dispatchCenter, new EmergencyPolicyDefault());
		setNumberOfCars(numberOfCars);
		setNumberOfInjured(numberOfInjured);
	}

	/**
	 * Getter for getting the amount of cars involved in this TrafficAccident
	 * 
	 * @return Returns the amount of cars involved in this TrafficAccident
	 */
	public int getNumberOfCars() {
		return numberOfCars;
	}

	/**
	 * Getter for getting the amount of people injured in this TrafficAccident
	 * 
	 * @return Returns the amount of people injured in this TrafficAccident
	 */
	public int getNumberOfInjured() {
		return numberOfInjured;
	}

	/**
	 * Method for setting this TrafficAccident his amount of involved cars
	 * 
	 * @param numberOfCars
	 *            The amount of cars involved in this TrafficAccident
	 * 
	 * @post The amount of cars involved is set to the given amount
	 * 
	 * @throws IllegalArgumentException
	 *             , if the given amount is not valid
	 */
	private void setNumberOfCars(int numberOfCars) {
		if (numberOfCars >= 0)
			this.numberOfCars = numberOfCars;
		else
			throw new IllegalArgumentException("Amounts cannot be negative");
	}

	/**
	 * Method for setting this TrafficAccident his amount of injured people
	 * 
	 * @param numberOfInjured
	 *            The amount of injured people in this TrafficAccident
	 * 
	 * @post The amount of people injured is set to the given amount
	 * 
	 * @throws IllegalArgumentException
	 *             , if the given amount is not valid
	 */
	private void setNumberOfInjured(int numberOfInjured) {
		if (numberOfInjured >= 0)
			this.numberOfInjured = numberOfInjured;
		else
			throw new IllegalArgumentException("Amounts cannot be negative");
	}

	/**
	 * Method for creating an description of this TrafficAccident
	 * 
	 * @return Returns the description of this TrafficAccident
	 */
	@Override
	public String toString() {
		String output = "severity is " + getSeverity().toString() + "  =  ";
		output += "TRAFFIC ACCIDENT ";
		if (numberOfCars > 0) {
			output += numberOfCars + " cars involved ";
		}
		if (numberOfInjured > 0) {
			output += numberOfInjured + " ppl involved";
		}
		return output;
	}

}
